1 Imports System.Data.OleDb
2 Imports System.IO
3
4 Public Class frmRestaurantMaster
5 Sub Reset()
6 txtSTNo.Text = ""
7 txtTIN.Text = ""
8 txtEmailID.Text = ""
9 txtContactNo.Text = ""
10 txtHotelName.Text = ""
11 txtCIN.Text = ""
12 txtAddressLine1.Text = ""
13 PictureBox1.Image = My.Resources.hotel_icon1
14 txtBaseCurrency.Text = ""
15 txtCurrencyCode.Text = ""
16 txtAddressLine2.Text = ""
17 txtAddressLine3.Text = ""
18 txtTicketFooterMessage.Text = ""
19 txtStartBillNo.Text = 1
20 txtStartBillNo.ReadOnly = False
21 txtStartBillNo.Enabled = True
22 btnSave.Enabled = True
23 btnUpdate.Enabled = False
24 btnDelete.Enabled = False
25 txtHotelName.Focus()
26 End Sub
27
28 Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
29 Me.Close()
30 End Sub
31
32 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
33 If txtHotelName.Text = "" Then
34 MessageBox.Show("Please enter restaurant name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
35 txtHotelName.Focus()
36 Return
37 End If
38 If txtAddressLine1.Text = "" Then
39 MessageBox.Show("Please enter address line 1", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
40 txtAddressLine1.Focus()
41 Return
42 End If
43 If txtAddressLine2.Text = "" Then
44 MessageBox.Show("Please enter address line 2", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
45 txtAddressLine2.Focus()
46 Return
47 End If
48 If txtContactNo.Text = "" Then
49 MessageBox.Show("Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
50 txtContactNo.Focus()
51 Return
52 End If
53
54 If txtEmailID.Text = "" Then
55 MessageBox.Show("Please enter email id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
56 txtEmailID.Focus()
57 Return
58 End If
59 If txtBaseCurrency.Text = "" Then
60 MessageBox.Show("Please enter base currency", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
61 txtBaseCurrency.Focus()
62 Return
63 End If
64 If txtCurrencyCode.Text = "" Then
65 MessageBox.Show("Please enter currency code", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
66 txtCurrencyCode.Focus()
67 Return
68 End If
69 Try
70 con = New OleDbConnection(cs)
71 con.Open()
72 Dim ct As String = "select count(*) from Hotel Having count(*) >= 1"
73 cmd = New OleDbCommand(ct)
74 cmd.Connection = con
75 rdr = cmd.ExecuteReader()
76 If rdr.Read Then
77 MessageBox.Show("Record Already Exists" & vbCrLf & "please update the restautant info", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
78 If Not rdr Is Nothing Then
79 rdr.Close()
80 End If
81 Exit Sub
82 End If
83 con = New OleDbConnection(cs)
84 con.Open()
85 Dim cb As String = "insert into Hotel( HotelName, AddressLine1, ContactNo, EmailID, TIN, STNo, CIN,BaseCurrency,CurrencyCode,AddressLine2,AddressLine3,TicketFooterMessage,StartBillNo,Logo) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14)"
86 cmd = New OleDbCommand(cb)
87 cmd.Connection = con
88 cmd.Parameters.AddWithValue("@d1", txtHotelName.Text)
89 cmd.Parameters.AddWithValue("@d2", txtAddressLine1.Text)
90 cmd.Parameters.AddWithValue("@d3", txtContactNo.Text)
91 cmd.Parameters.AddWithValue("@d4", txtEmailID.Text)
92 cmd.Parameters.AddWithValue("@d5", txtTIN.Text)
93 cmd.Parameters.AddWithValue("@d6", txtSTNo.Text)
94 cmd.Parameters.AddWithValue("@d7", txtCIN.Text)
95 cmd.Parameters.AddWithValue("@d8", txtBaseCurrency.Text)
96 cmd.Parameters.AddWithValue("@d9", txtCurrencyCode.Text)
97 cmd.Parameters.AddWithValue("@d10", txtAddressLine2.Text)
98 cmd.Parameters.AddWithValue("@d11", txtAddressLine3.Text)
99 cmd.Parameters.AddWithValue("@d12", txtTicketFooterMessage.Text)
100 cmd.Parameters.AddWithValue("@d13", txtStartBillNo.Text)
101 Dim ms As New MemoryStream()
102 Dim bmpImage As New Bitmap(PictureBox1.Image)
103 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
104 Dim data As Byte() = ms.GetBuffer()
105 Dim p As New OleDbParameter("@d14", OleDbType.VarBinary)
106 p.Value = data
107 cmd.Parameters.Add(p)
108 cmd.ExecuteNonQuery()
109 con.Close()
110 Dim st As String = "added the restaurant '" & txtHotelName.Text & "' info"
111 LogFunc(lblUser.Text, st)
112 MessageBox.Show("Successfully saved", "Restaurant Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
113 btnSave.Enabled = False
114 Getdata()
115 Reset()
116 Catch ex As Exception
117 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
118 End Try
119 End Sub
120
121 Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
122 If txtHotelName.Text = "" Then
123 MessageBox.Show("Please enter restaurant name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
124 txtHotelName.Focus()
125 Return
126 End If
127 If txtAddressLine1.Text = "" Then
128 MessageBox.Show("Please enter address line 1", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
129 txtAddressLine1.Focus()
130 Return
131 End If
132 If txtAddressLine2.Text = "" Then
133 MessageBox.Show("Please enter address line 2", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
134 txtAddressLine2.Focus()
135 Return
136 End If
137 If txtContactNo.Text = "" Then
138 MessageBox.Show("Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
139 txtContactNo.Focus()
140 Return
141 End If
142
143 If txtEmailID.Text = "" Then
144 MessageBox.Show("Please enter email id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
145 txtEmailID.Focus()
146 Return
147 End If
148 If txtBaseCurrency.Text = "" Then
149 MessageBox.Show("Please enter base currency", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
150 txtBaseCurrency.Focus()
151 Return
152 End If
153 If txtCurrencyCode.Text = "" Then
154 MessageBox.Show("Please enter currency code", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
155 txtCurrencyCode.Focus()
156 Return
157 End If
158 Try
159 con = New OleDbConnection(cs)
160 con.Open()
161 Dim cb As String = "Update Hotel set HotelName=@d1, AddressLine1=@d2, ContactNo=@d3, EmailID=@d4, TIN=@d5, STNo=@d6, CIN=@d7,BaseCurrency=@d8,CurrencyCode=@d9,AddressLine2=@d10,AddressLine3=@d11,TicketFooterMessage=@d12,Logo=@d13 where ID=" & txtID.Text & ""
162 cmd = New OleDbCommand(cb)
163 cmd.Connection = con
164 cmd.Parameters.AddWithValue("@d1", txtHotelName.Text)
165 cmd.Parameters.AddWithValue("@d2", txtAddressLine1.Text)
166 cmd.Parameters.AddWithValue("@d3", txtContactNo.Text)
167 cmd.Parameters.AddWithValue("@d4", txtEmailID.Text)
168 cmd.Parameters.AddWithValue("@d5", txtTIN.Text)
169 cmd.Parameters.AddWithValue("@d6", txtSTNo.Text)
170 cmd.Parameters.AddWithValue("@d7", txtCIN.Text)
171 cmd.Parameters.AddWithValue("@d8", txtBaseCurrency.Text)
172 cmd.Parameters.AddWithValue("@d9", txtCurrencyCode.Text)
173 cmd.Parameters.AddWithValue("@d10", txtAddressLine2.Text)
174 cmd.Parameters.AddWithValue("@d11", txtAddressLine3.Text)
175 cmd.Parameters.AddWithValue("@d12", txtTicketFooterMessage.Text)
176 Dim ms As New MemoryStream()
177 Dim bmpImage As New Bitmap(PictureBox1.Image)
178 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
179 Dim data As Byte() = ms.GetBuffer()
180 Dim p As New OleDbParameter("@d13", OleDbType.VarBinary)
181 p.Value = data
182 cmd.Parameters.Add(p)
183 cmd.ExecuteNonQuery()
184 con.Close()
185 Dim st As String = "updated the restaurant '" & txtHotelName.Text & "' info"
186 LogFunc(lblUser.Text, st)
187 MessageBox.Show("Successfully updated", "Restaurant Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
188 btnUpdate.Enabled = False
189 Getdata()
190 Catch ex As Exception
191 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
192 End Try
193 End Sub
194
195 Public Sub Getdata()
196 Try
197 con = New OleDbConnection(cs)
198 con.Open()
199 cmd = New OleDbCommand("SELECT RTRIM(ID), RTRIM(HotelName), RTRIM(AddressLine1),RTRIM(AddressLine2),RTRIM(AddressLine3), RTRIM(ContactNo), RTRIM(EmailID), RTRIM(TIN), RTRIM(STNo), RTRIM(CIN),RTRIM(BaseCurrency),RTRIM(CurrencyCode),RTRIM(TicketFooterMessage),StartBillNo,Logo from Hotel", con)
200 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
201 dgw.Rows.Clear()
202 While (rdr.Read() = True)
203 dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11), rdr(12), rdr(13), rdr(14))
204 End While
205 con.Close()
206 Catch ex As Exception
207 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
208 End Try
209 End Sub
210
211 Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
212 Reset()
213 End Sub
214
215 Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
216 Dim strRowNumber As String = (e.RowIndex + 1).ToString()
217 Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
218 If dgw.RowHeadersWidth < Convert.ToInt32((size.Width + 20)) Then
219 dgw.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
220 End If
221 Dim b As Brush = SystemBrushes.ControlText
222 e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
223
224 End Sub
225
226 Private Sub frmRestaurantMaster_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
227 If e.KeyCode = Keys.Enter Then
228 Me.SelectNextControl(Me.ActiveControl, True, True, True, False) 'for Select Next Control
229 End If
230 End Sub
231
232 Private Sub frmRegistration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
233 Getdata()
234 End Sub
235
236 Private Sub dgw_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
237 Try
238 If dgw.Rows.Count > 0 Then
239 Dim dr As DataGridViewRow = dgw.SelectedRows(0)
240 txtID.Text = dr.Cells(0).Value.ToString()
241 txtHotelName.Text = dr.Cells(1).Value.ToString()
242 txtAddressLine1.Text = dr.Cells(2).Value.ToString()
243 txtAddressLine2.Text = dr.Cells(3).Value.ToString()
244 txtAddressLine3.Text = dr.Cells(4).Value.ToString()
245 txtContactNo.Text = dr.Cells(5).Value.ToString()
246 txtEmailID.Text = dr.Cells(6).Value.ToString()
247 txtTIN.Text = dr.Cells(7).Value.ToString()
248 txtSTNo.Text = dr.Cells(8).Value.ToString()
249 txtCIN.Text = dr.Cells(9).Value.ToString()
250
251 txtBaseCurrency.Text = dr.Cells(10).Value.ToString()
252 txtCurrencyCode.Text = dr.Cells(11).Value.ToString()
253 txtcCode.Text = dr.Cells(11).Value.ToString()
254 txtTicketFooterMessage.Text = dr.Cells(12).Value.ToString()
255 txtStartBillNo.Text = dr.Cells(13).Value.ToString()
256 Dim data As Byte() = DirectCast(dr.Cells(14).Value, Byte())
257 Dim ms As New MemoryStream(data)
258 Me.PictureBox1.Image = Image.FromStream(ms)
259 btnUpdate.Enabled = True
260 btnSave.Enabled = False
261 btnDelete.Enabled = True
262 txtStartBillNo.ReadOnly = True
263 txtStartBillNo.Enabled = False
264 End If
265 Catch ex As Exception
266 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
267 End Try
268 End Sub
269
270 Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
271 Try
272 With OpenFileDialog1
273 .Filter = ("Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif;*.ico;")
274 .FilterIndex = 4
275 End With
276 'Clear the file name
277 OpenFileDialog1.FileName = ""
278 If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
279 PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
280 End If
281 Catch ex As Exception
282 MsgBox(ex.ToString())
283 End Try
284 End Sub
285
286 Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
287 Try
288 If MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
289 DeleteRecord()
290 End If
291 Catch ex As Exception
292 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
293 End Try
294 End Sub
295
296 Private Sub DeleteRecord()
297 Try
298 Dim RowsAffected As Integer = 0
299 con = New OleDbConnection(cs)
300 con.Open()
301 Dim cq As String = "delete from Hotel where ID=@d1"
302 cmd = New OleDbCommand(cq)
303 cmd.Connection = con
304 cmd.Parameters.AddWithValue("@d1", Val(txtID.Text))
305 RowsAffected = cmd.ExecuteNonQuery()
306 If RowsAffected > 0 Then
307 Dim st As String = "deleted the restaurant '" & txtHotelName.Text & "' info"
308 LogFunc(lblUser.Text, st)
309 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
310 Getdata()
311 Reset()
312 Else
313 MessageBox.Show("No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
314 Reset()
315 End If
316 If con.State = ConnectionState.Open Then
317 con.Close()
318
319 End If
320 Catch ex As Exception
321 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
322 End Try
323 End Sub
324
325 Private Sub txtStartBillNo_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtStartBillNo.KeyPress
326 If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8) Then
327 e.Handled = True
328 End If
329 End Sub
330 End Class